#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <map>
using std::cout;
using std::endl;
using std::cerr;
using std::string;
using std::ifstream;
using std::map;
using std::istringstream;


const string& transword(const string &line,const map<string,string> & m){
    auto it = m.find(line);
    if(it != m.end()){
        return m.find(line)->second;
    }else{
        return line;
    }
}

map<string,string> buildMap(ifstream & map_file){
    map<string,string> trans_map;
    string key;
    string value;
    while(map_file >> key && getline(map_file,value)){
        if(value.size() > 1){
            trans_map[key] = value.substr(1);
        }
    }
    return trans_map;

}

void map_transword(ifstream & map_file, ifstream & input){
    map<string,string> trans_map = buildMap(map_file);
    string line;
    while(getline(input,line)){
        istringstream iss(line);
        string word;
        bool firstword = true;
        while(iss >> word){
            //如果不是第一个单词 打印空格
            if(firstword){
                firstword = false;
            }else{
                cout << " ";
            }

            cout << transword(word,trans_map);
        }

        cout << endl;
    }
}

/* map<string,string> buildMap(ifstream & map_file){ */
/*     map<string,string> trans_map; */
/*     string key; */
/*     string value; */
/*     while(map_file >> key && getline(map_file,value)){ */
/*         if(value.size() > 1){ */
/*             trans_map[key] = value.substr(1); */
/*         } */
/*     } */
/*     return trans_map; */
/* } */

/* const string& transword(const string &line,const map<string,string> & m){ */
/*     auto it = m.find(line); */
/*     if(it != m.end()){ */
/*         return m.find(line)->second; */
/*     }else{ */
/*         return line; */
/*     } */
/* } */

void test0(){
    ifstream ifs("map.txt");
    ifstream ifs2("file.txt");
    map_transword(ifs,ifs2);
}

int main(int argc, char * argv[])
{
    test0();
    return 0;
}


